package com.interagriculture.controller;

import com.interagriculture.annotation.AdminVerify;
import com.interagriculture.common.Result;
import com.interagriculture.entity.Dfw;
import com.interagriculture.service.DfwService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/dfw")
@RestController
@Slf4j
public class DfwController {

    @Autowired
    private DfwService dfwService;

    /**
     * 获取所有信息
     * @return
     */
    @GetMapping("/getAll")
    public Result<List<Dfw>> getAll(){
        List<Dfw> dfwList = dfwService.getAll();
        return Result.ok(dfwList);
    }

    /**
     * 新增或修改
     */
    @AdminVerify
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Dfw dfw){
        dfwService.saveOrUpdate(dfw);
        return Result.ok();
    }

    /**
     * 删除一条信息
     */
    @AdminVerify
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        dfwService.delete(id);
        return Result.ok();
    }

}
